package class03;

import java.util.Stack;

public class Code06_TwoStacksImplementQueue {
    public static class TwoStacksQueue{
        public Stack<Integer> stackPush;
        public Stack<Integer> stackPop;

        public TwoStacksQueue(){
            stackPush=new Stack<Integer>();
            stackPop=new Stack<Integer>();
        }

        private void pushToPop(){
            if (stackPop.empty()){
                while (!stackPush.empty()){
                    stackPop.push(stackPush.pop());
                }
            }
        }

        public void add(int pushInt){
            stackPush.push(pushInt);
            pushToPop();
        }

        public int poll(){
            if (stackPop.empty()&&stackPush.empty()){
                throw new RuntimeException("你的队列是空的");
            }
            pushToPop();
            return stackPop.pop();
        }

        public int peek(){
            if (stackPop.empty()&&stackPush.empty()){
                throw new RuntimeException("你的队列是空的");
            }
            pushToPop();
            return stackPop.peek();
        }
    }
}
